package com.yqw.onlineDocs.manager.websocket.model;

import lombok.Getter;

/**
 * 文档编辑消息类型枚举
 */
@Getter
public enum DocumentEditMessageTypeEnum {
  INIT("初始化连接", "init"),
  INFO("发送通知", "INFO"),
  ERROR("发送错误", "ERROR"),
  ENTER_EDIT("进入编辑状态", "ENTER_EDIT"),
  EXIT_EDIT("退出编辑状态", "EXIT_EDIT"),
  EDIT_ACTION("执行编辑操作", "EDIT_ACTION"),
  CURSOR_MOVE("光标移动", "CURSOR_MOVE"),
  SELECTION_CHANGE("选择区域变化", "SELECTION_CHANGE"),
  SAVE_VERSION("保存版本", "SAVE_VERSION");

  private String text;
  private String value;

  DocumentEditMessageTypeEnum(String text, String value) {
    this.text = text;
    this.value = value;
  }

  /**
   * 根据value获取枚举类型
   *
   * @param value
   * @return
   */
  public static DocumentEditMessageTypeEnum getEnumByValue(String value) {
    if (value == null || value.isEmpty()) {
      return null;
    }
    for (DocumentEditMessageTypeEnum typeEnum : DocumentEditMessageTypeEnum.values()) {
      if (typeEnum.value.equals(value)) {
        return typeEnum;
      }
    }
    return null;
  }
}
